﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using XXX.Models.XXXEntities;
using XXX.Bo;
using XXX.Models;
using fuzhu;
using NetTaste;
using Yonyou.U8.BO;
using Newtonsoft.Json.Linq;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace XXX.api.Controllers
{
    //读取现存量
    [Route("api/wms/[controller]")]
    [ApiController]
    //[Authorize]
    public class GetRepInvStockController : ControllerBase
    {
        //private readonly IKuCunReqRepository _invRepository;
        private readonly ILogger<GetRepInvStockController> _logger;
        public GetRepInvStockController(ILogger<GetRepInvStockController> logger)
        {
            //_invRepository = xxxRepository;
            _logger = logger;
        }


        [HttpPost]
        public Models.RetModel<ReportInvStock> Post(JObject obj)
        {

            string requestBody = DbHelper.GetDbString(obj);

            if (requestBody == null)
            {
                return DBService.ReError<ReportInvStock>("入参有误，没有数据");
            }
            try
            {
                string cErr = "";
                StockReportQuery model = JsonConvert.DeserializeObject<StockReportQuery>(requestBody);

                Models.RetModel<ReportInvStock> ret = DBService.Rep_GetInvStock("", model.WHCODE, model.INVCODE);

                return ret;
            }
            catch (Exception ex)
            {

                return DBService.ReError<ReportInvStock>(ex.Message);
            }
            
           
           
        }

    }




    //读取货位条码信息
    [Route("api/wms/[controller]")]
    [ApiController]
    //[Authorize]
    public class GetRepPosStockController : ControllerBase
    {
        //private readonly IKuCunReqRepository _invRepository;
        private readonly ILogger<GetRepPosStockController> _logger;
        public GetRepPosStockController(ILogger<GetRepPosStockController> logger)
        {
            //_invRepository = xxxRepository;
            _logger = logger;
        }


        [HttpPost]
        public Models.RetModel<ReportInvStock> Post(JObject obj)
        {
            string requestBody = DbHelper.GetDbString(obj);

            if (requestBody == null)
            {
                return DBService.ReError<ReportInvStock>("入参有误，没有数据");
            }
            try
            {
                string cErr = "";
                StockReportQuery model = JsonConvert.DeserializeObject<StockReportQuery>(requestBody);

                Models.RetModel<ReportInvStock> ret = DBService.Rep_GetInvPosStock("", model.WHCODE, model.CPOSCODE, model.INVCODE);

                return ret;
            }
            catch (Exception ex)
            {

                return DBService.ReError<ReportInvStock>(ex.Message);
            }
         
          
        }

    }




    //条码和现存量对比
    [Route("api/wms/[controller]")]
    [ApiController]
    //[Authorize]
    public class GetU8StockDuiBiController : ControllerBase
    {
        //private readonly IKuCunReqRepository _invRepository;
        private readonly ILogger<GetU8StockDuiBiController> _logger;
        public GetU8StockDuiBiController(ILogger<GetU8StockDuiBiController> logger)
        {
            //_invRepository = xxxRepository;
            _logger = logger;
        }


        [HttpPost]
        public Models.RetModel<Rep_U8StockDuiBi> Post(JObject obj)
        {
            string requestBody = DbHelper.GetDbString(obj);

            if (requestBody == null)
            {
                return DBService.ReError<Rep_U8StockDuiBi>("入参有误，没有数据");
            }
            try
            {
                string cErr = "";
                Rep_U8StockDuiBi model = JsonConvert.DeserializeObject<Rep_U8StockDuiBi>(requestBody);
                WMS_PanDianVM wMS_PanDianVM = new WMS_PanDianVM();

                Models.RetModel<Rep_U8StockDuiBi> ret = wMS_PanDianVM.Rep_BarcodeU8StockDuiBi(model);


                return ret;
            }
            catch (Exception ex)
            {

                return DBService.ReError<Rep_U8StockDuiBi>(ex.Message);
            }


        }

    }



    //条码和货位现存量对比
    [Route("api/wms/[controller]")]
    [ApiController]
    //[Authorize]
    public class GetU8PosStockDuiBiController : ControllerBase
    {
        //private readonly IKuCunReqRepository _invRepository;
        private readonly ILogger<GetU8PosStockDuiBiController> _logger;
        public GetU8PosStockDuiBiController(ILogger<GetU8PosStockDuiBiController> logger)
        {
            //_invRepository = xxxRepository;
            _logger = logger;
        }


        [HttpPost]
        public Models.RetModel<Rep_U8StockDuiBi> Post(JObject obj)
        {
            string requestBody = DbHelper.GetDbString(obj);

            if (requestBody == null)
            {
                return DBService.ReError<Rep_U8StockDuiBi>("入参有误，没有数据");
            }
            try
            {
                string cErr = "";
                Rep_U8StockDuiBi model = JsonConvert.DeserializeObject<Rep_U8StockDuiBi>(requestBody);
                WMS_PanDianVM wMS_PanDianVM = new WMS_PanDianVM();

                Models.RetModel<Rep_U8StockDuiBi> ret = wMS_PanDianVM.Rep_BarcodeU8PosStockDuiBi(model);


                return ret;
            }
            catch (Exception ex)
            {

                return DBService.ReError<Rep_U8StockDuiBi>(ex.Message);
            }


        }

    }


    





}
